FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
IF(NOT GETTEXT_MSGMERGE_EXECUTABLE)
	MESSAGE("NOTE: msgmerge not found.")
ELSE(NOT GETTEXT_MSGMERGE_EXECUTABLE)
	ADD_CUSTOM_TARGET(update_translations ALL)
	FILE(GLOB PO_FILES ${catalogname}*.po)
	FOREACH(_poFile ${PO_FILES})
		ADD_CUSTOM_COMMAND(TARGET update_translations
						   COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} -U --backup=off ${_poFile} ${CMAKE_CURRENT_SOURCE_DIR}/messages.pot
						   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/messages.pot)
	ENDFOREACH(_poFile ${PO_FILES})	
ENDIF(NOT GETTEXT_MSGMERGE_EXECUTABLE)

FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
IF(NOT GETTEXT_MSGFMT_EXECUTABLE)
	MESSAGE("------\n   NOTE: msgfmt not found. Translations will *not* be installed\n------")
ELSE(NOT GETTEXT_MSGFMT_EXECUTABLE)
	SET(catalogname plasma_applet_salatinoid)
	ADD_CUSTOM_TARGET(translations ALL) 
	FILE(GLOB PO_FILES ${catalogname}*.po)
	FOREACH(_poFile ${PO_FILES})
		GET_FILENAME_COMPONENT(_poFileName ${_poFile} NAME)
		STRING(REGEX REPLACE "^${catalogname}_?" "" _langCode ${_poFileName} )
		STRING(REGEX REPLACE "\\.po$" "" _langCode ${_langCode} )
		IF( _langCode )
			GET_FILENAME_COMPONENT(_lang ${_poFile} NAME_WE)
			SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
			ADD_CUSTOM_COMMAND(TARGET translations
			COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${_gmoFile} ${_poFile}
			DEPENDS ${_poFile})
			INSTALL(FILES ${_gmoFile} DESTINATION ${LOCALE_INSTALL_DIR}/${_langCode}/LC_MESSAGES/ RENAME ${catalogname}.mo)
		ENDIF( _langCode )
	ENDFOREACH(_poFile ${PO_FILES})
ENDIF(NOT GETTEXT_MSGFMT_EXECUTABLE) 
